package com.dao;

import com.entity.User;
import com.service.CalculateSalary;
import com.util.DBUtil;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.junit.Test;

public class LoginDao {

	public static User logincheck(String userid,String pwd) {
		boolean action = false;
		PreparedStatement pst = null;
		ResultSet rs = null;
		User user = null;
		String sql = null;
		try {
			sql = "SELECT * FROM user,deptrole where user.deptid=deptrole.deptid and user.roleid=deptrole.roleid and Userid='" + userid + "' and Pwd='" + pwd + "'";
			pst = DBUtil.getConnection().prepareStatement(sql);
			rs = pst.executeQuery(sql);
			while(rs.next())
			{
				user = new User();
				user.setUserid(rs.getString("Userid"));
				user.setDeptid(rs.getString("Deptid"));
				user.setDeptname(rs.getString("Deptname"));
				user.setRoleid(rs.getString("Roleid"));
				user.setRolename(rs.getString("Rolename"));
				user.setStatus(rs.getString("Status"));
				user.setName(rs.getString("Name"));
				user.setSex(rs.getString("Sex"));
				user.setAge(rs.getInt("Age"));
				user.setPhone(rs.getString("Phone"));
				user.setCreatetime(rs.getString("Create_time"));
				user.setBasewages(rs.getFloat("Basewages"));
				user.setMeritwages(rs.getFloat("Meritwages"));
				user.setPunishingwages(rs.getFloat("Punishingwages"));
				user.setTotalwages(rs.getFloat("Totalwages"));
				user.setOvertime(rs.getInt("Overtime"));
				user.setWeekovertime(rs.getInt("Weekovertime"));
				user.setFestovertime(rs.getInt("Festovertime"));
				user.setOvertimestandard(rs.getFloat("Overtimestandard"));
				user.setCommission(rs.getFloat("Commission"));
				user.setFestivalwages(rs.getFloat("Festivalwages"));
				user.setYearendwages(rs.getFloat("Yearendwages"));
				user.setLeavecount(rs.getInt("Leavecount"));
				user.setAbsentcount(rs.getInt("Absentcount"));
				user.setLeavestandard(rs.getFloat("Leavestandard"));
				user.setAbsentstandard(rs.getFloat("Absentstandard"));
				user = CalculateSalary.calculate(user);
				action = true;
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return user;
		
	}
//	@Test
//	public void test() {
//		System.out.println(logincheck("123","123"));
//	}
}
